package manager.event;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import manager.data.RawDataObject;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import store.hibernate.Evento;

public class EventObject {
	
	private SessionFactory factory;

	public EventObject(){
		try { 
			InitialContext ctx = new InitialContext(); 
			factory = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactory"); 
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public boolean insertBlock(RawDataObject rdo) {
		Session session = factory.openSession();
	     session.beginTransaction();
	    	 Evento eq = new Evento(rdo.getKey(), 
	    			 rdo.getWSObject(), rdo.getUserObject(), rdo.getOperationObject(),
	    			 rdo.getDirection(), rdo.getTimestamp(), rdo.getSession(),
	    			 rdo.getSeqNumber()
	    	 );
	    	// if(rdo.getParams()!=null)
	    	//	 eq.setParametriByte(rdo.getParams());
	    	 session.save(eq);
	    	 System.out.println("inserisco in evento record...");

	  //   }
	     session.getTransaction().commit();
	     if (session.isOpen()) 
	    	 session.close(); 
	     return true;
	}
	
}
